package com.ys.config.database;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfiguration {

    // Primary注解是在没有指明使用哪个数据源的时候指定默认使用的主数据源
    @Primary
    @Bean("primaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.primary")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }

//    @Bean("secondaryDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.slave")
//    public DataSource secondaryDataSource() {
//        return DataSourceBuilder.create().build();
//    }
}
